package com.example.demoaop.config.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * @ClassName EatAspect
 * @Description TODO
 * @Author leejiliang
 * @DateTime 2020/8/31 9:44 AM
 * @Version 1.0
 */
@Aspect
public class EatAspect {

	@Pointcut("execution(* com.example.demoaop.service.HumanImpl.eat(..))")
	public void pointCut() {}

	@Before("pointCut() && args(foodName)")
	public void before(JoinPoint joinPoint, String foodName) {
		for (Object arg : joinPoint.getArgs()) {
			System.out.println(arg.toString());
		}
		System.out.println("先做饭, 做: "+foodName);
	}

	@Around("pointCut()")
	public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
		System.out.println("先洗菜");
		Object[] args = proceedingJoinPoint.getArgs();
		for (Object arg : args) {
			System.out.println(arg.toString());
		}
		proceedingJoinPoint.proceed();
		System.out.println("吃完饭要洗碗");
	}

	@After("pointCut()")
	public void after(JoinPoint joinPoint) {
		for (Object arg : joinPoint.getArgs()) {
			System.out.println("After :" +arg.toString());
		}
	}


}
